package com.uton.rfidcontroller.common.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.uton.rfidcontroller.common.GlobalConstants;
import com.uton.rfidcontroller.common.MyApplication;

/**
 * Created by 王家宝 on 2017/9/29.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public class SharedPreferencesUtils {


    /**
     * 保存Token
     *
     * @param token
     */
    public static void saveToken(String token) {
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences(GlobalConstants.TOKEN, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(GlobalConstants.TOKEN, token);
        editor.commit();
    }


    /**
     * 获取Token
     *
     * @return
     */
    public static String getToken() {
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences(GlobalConstants.TOKEN, Context.MODE_PRIVATE);
        return sp.getString(GlobalConstants.TOKEN, "");
//        return "40ef508472bb4d318cbc5851cc7b4e5f";
    }

    /**
     * 清除Token
     *
     * @return
     */
    public static void clearToken() {
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences(GlobalConstants.TOKEN, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear().commit();
    }


    /**
     * 保存UserID
     *
     * @param token
     */
    public static void saveUserID(String token) {
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences(GlobalConstants.USER_ID, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(GlobalConstants.USER_ID, token);
        editor.commit();
    }


    /**
     * 获取UserID
     *
     * @return
     */
    public static String getUserID() {
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences(GlobalConstants.USER_ID, Context.MODE_PRIVATE);
        return sp.getString(GlobalConstants.USER_ID, "");
//        return "1";
    }


    /**
     * 获取UserID
     *
     * @return
     */
    public static void clearUserID() {
        SharedPreferences sp = MyApplication.getContext().getSharedPreferences(GlobalConstants.USER_ID, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear().commit();
    }


}
